package com.example.home_stretch;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Sjzx extends AppCompatActivity {
    @BindView(R.id.bu_zc)
    Button buZc;
    private TextView tv_zc1;
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(Sjzx.this);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sjzx);
        initView();
        ButterKnife.bind(this);
        //并且在Activity或者Fragment生命周期中绑定监听
        EventBus.getDefault().register(Sjzx.this);
        //并且在Activity或者Fragment生命周期中取消监听
        //EventBus.getDefault().unregister(Sjzx.this);
    }
    //创建观察者
    // 当MessageEvent被当做参数发送的时候这个方法将会被触发.message是我创建的那个实力类对象的名字
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        //把发送消息的内容发送到，tv_zcl是一个Text文本
        tv_zc1.setText(event.getMessage());
    }
    //跳转到发送广播的页面
    @OnClick(R.id.bu_zc)
    public void onViewClicked() {
        startActivity(new Intent(Sjzx.this, Sjzx_fsgb.class));
    }
    //实例化对象
    private void initView() {
        tv_zc1 = (TextView) findViewById(R.id.tv_zc1);
    }
}
